package com.sky.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 订单表
 *
 * @Author mr.lcc
 * @Data 2025/5/26 20:45
 */
public interface OrderMapper extends BaseMapper<Orders> {

    /**
     * 销售额统计
     *
     * @param map
     * @return
     */
    Double sumByMap(Map map);


    /**
     * 统计总订单
     *
     * @param begin
     * @param end
     * @return
     */
    @Select("select count(id) from orders where order_time > #{begin} and order_time < #{end}")
    Integer allCountOrders(@Param("begin") LocalDateTime begin, @Param("end") LocalDateTime end);

    /**
     * 有效订单数量
     *
     * @param begin
     * @param end
     * @return
     */
    @Select("select count(id) from orders where order_time > #{begin} and order_time < #{end} and status = 5 ")
    Integer validCountOrders(@Param("begin") LocalDateTime begin, @Param("end") LocalDateTime end);

    /**
     * 查询订单销量
     *
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> selectTop(@Param("begin") LocalDateTime begin, @Param("end") LocalDateTime end);

    /**
     * 根据动态条件统计订单数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
